package cn.itcast.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.net.URL;
import java.util.Arrays;

public class ContextLoaderListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("正在准备读取、解析配置文件");
        String location = sce.getServletContext().getInitParameter("contextConfigLocation");
        if (location.startsWith("classpath")) {
            String path = ContextLoaderListener.class.getClassLoader().getResource(location.substring(10)).getPath();
            System.out.println("正在解析" + path +"文件");
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
